package lanQiaoBei.数据结构.链表;
import java.io.*;
/*
* 使用数组实现一个单链表
* */
public class P1 {
       final static int N=100010;
       static int head,idx;
       static int[]e=new int[N],ne=new int[N];
       //初始化
       public static void init(){
              head=-1;
              idx=0;
       }
       //头插
       public static void insert_head(int x){
              e[idx]=x;
              ne[idx]=head;
              head=idx;
              idx++;
       }
       //在下标为k的位置后插
       public static void insert_k(int k,int x){
              if(k<0)return;
              e[idx]=x;
              ne[idx]=ne[k];
              ne[k]=idx;
              idx++;
       }
       //将下标为K的下一个数删除
       public static int remove_k(int k){
              int res=0;
              res=e[ne[k]];
              ne[k]=ne[ne[k]];
              return res;
       }
       public static void scan()throws Exception{
              init();
              BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
              int n=Integer.parseInt(br.readLine());
              for(int i=0;i<n;i++){
                  String[] ss = br.readLine().split(" ");
                  if("H".equals(ss[0])){
                      insert_head(Integer.parseInt(ss[1]));
                  }else if("D".equals(ss[0])){
                        if("0".equals(ss[1]))head=ne[head];
                        else{
                            remove_k(Integer.parseInt(ss[1])-1);
                        }
                  }else{
                      insert_k(Integer.parseInt(ss[1])-1,Integer.parseInt(ss[2]));
                  }
              }
       }
       public static void main(String[]args)throws Exception{
           scan();
           for(int i=head;i!=-1;){
               System.out.print(e[i]+" ");
               i=ne[i];
           }
       }

}
